import { reqCategoryList, reqGetBannerList,reqFloorList } from "@/api";
//home模块的小仓库

//准备state——用于存储数据
const state = {
    categoryList: [],   //home仓库中三级菜单的数据
    bannerList: [],     //轮播图数据
    floorList:[]        //floor组件数据
}

//准备mutations——用于操作数据（state）
const mutations = {
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList
    },
    GETBANNERLIST(state, bannerList) {
        state.bannerList = bannerList
    },
    GETFLOORLIST(state,floorList){
        state.floorList =floorList
    }
}
//准备actions——用于响应组件中的动作
const actions = {
    //通过API里面的接口函数调用，向服务器发请求，获取服务器的数据

    async categoryList({ commit }) {
        let result = await reqCategoryList();      //async&await  es6
        if (result.code == 200) {
            commit("CATEGORYLIST", result.data)
        }
    },
    //获取首页轮播图的数据
    async getBannerList({ commit }) {
        let result = await reqGetBannerList();      //async&await  es6
        if (result.code == 200) {
            commit("GETBANNERLIST", result.data)
        }
    },
    //获取Floor数据
    async getFloorList({ commit }) {
        let result = await reqFloorList();      //async&await  es6
        if (result.code == 200) {
            commit("GETFLOORLIST", result.data)
        }
    },
    
}
//准备getters——用于将state中的数据进行加工
const getters = {

}
//暴露
export default ({
    actions,
    mutations,
    state,
    getters,
})